from faker import Faker
faker1=Faker(locale="zh_cn")   #设置成中国

import random

from datetime import datetime

#1、编写一个学生方法，产生一堆学生对象（姓名），传入形参控制学生生成数量
# def ins(n):
#     i=0
#
#     while i<n:
#         for j in range(1,n+1):
#             print(faker1.name())
#             i = i + 1
#
# ins(3)

#2、创建一个方法，用来生成信息：姓名、年龄、住址、身份证号、手机号，随机生成20个写入personinfo.txt里
#格式：姓名：xxx  年龄：xxx 住址：xxx 身份证号：xxx
# def ins():
#     i=0
#     list1=[]
#
#     while i<20:
#         name=faker1.name()
#         age=random.randint(18,35)
#         address=faker1.address()
#         card=faker1.ssn(min_age=18,max_age=35)
#         phone=faker1.phone_number()
#
#
#
#
#         str1=f"姓名:{name}  年龄:{age}   住址:{address}   身份证号:{card}   手机号:{phone}\n"
#         list1.append(str1)
#
#         i=i+1
#
#     with open("personinfo.txt","w",encoding="utf-8") as b:
#         b.writelines(list1)
#
# ins()
#
# with open("personinfo.txt", "r", encoding="utf-8") as b:
#     print(b.read())



#3、student.txt中包含下面的内容:
# zhangshan:30
# lisi:50
# wangwu:60
# lifei:70
#能统计出其中的内容，以dict的形式保存，例如： {"zhangshan":30,"lisi":50,"wangwu":60,"lifei":70}
# dict1={}
#
# with open("student.txt","r",encoding="utf-8") as a:
#      list1=a.readlines()   #字符串格式输出
#    #['zhangshan:30\n', 'lisi:50\n', 'wangwu:60\n', 'lifei:70']
# dict2={}
#
# for i in list1:    #方法一
#     b=i.strip()
#     print(b)
#     aaa=b.split(":")
#     print(aaa)
#     dict2[aaa[0]]=int(aaa[1])
# print(dict2)

# for i in list1:   #方法二
#     key,value=(i.strip()).split(":")
#     dict2[key]=int(value)
#     print(dict2)




#4、给你一个 非空 整数数组 nums ，除了某个元素只出现一次以外，其余每个元素均出现两次。找出那个只出现了一次的元素

# def ins(nums):
#     for i in nums:
#         if nums.count(i)!=2:
#             print(i)    #或者return i
#
# ins([1,2,2,3,3,4,4,5,5])



#5、输入：["1","a","b","3","5","8","_"] 想要提取里面得数字，并保存到一个列表中
# list1=["1","a","b","3","5","8","_"]     #方法一
# list2=[]
# for i in list1:
#     try:
#         a=int(i)
#         list2.append(a)
#     except:
#         pass
# print(list2)

# def ins(a:list)->list:       #方法二
#     list1=[]
#     for i in a:
#         if i in "0123456789":
#             list1.append(i)
#     return list1
# print(ins(["1","a","b","3","5","8","_"]))



#6、写函数,函数接收的4个参数分别是:姓名,性别(默认为男),年龄,地址
#用户通过input输入这4个内容(支持持续输入,Q或q退出)
#函数接收到这些内容,追加到student_msg文件中
# def ins():                 #方法一
#     while True:
#         name=input("请输入姓名:")
#         if name=="q" or name=="Q":
#             break
#         sex = input("请输入性别:")
#         if sex=="q" or sex=="Q":
#             break
#         if sex:   #布尔值,如果为True则pass
#             pass
#         else:
#             sex= "男"
#
#         age = input("请输入年龄:")
#         if age=="q" or age=="Q":
#             break
#         address = input("请输入地址:")
#         if address=="q" or address=="Q":
#             break
#
#         aaa=f"姓名:{name},性别:{sex},年龄:{age},地址:{address}\n"
#         print(f"{aaa}已生成并存入")
#
#         with open("student_msg", "a", encoding="utf-8") as b:
#             b.write(aaa)
#
# ins()



# def ins(name,age,sex="男"):     #方法二
#     with open("student_msg", "a", encoding="utf-8") as b:
#         b.write(f"姓名:{name},性别:{sex},年龄:{age}\n")
#         print(f"写入成功:姓名:{name},性别:{sex},年龄:{age}")
#
# while True:
#     name=input("请输入姓名:")
#     if name=="q" or name=="Q":
#         break
#
#     age = input("请输入年龄:")
#     if age == "q" or age == "Q":
#         break
#
#
#     sex=input("请输入性别:")
#     if sex=="q" or sex=="Q":
#         break
#
#     if sex:   #判断布尔值,如果True,则这里!!!!!!
#         ins(name,age,sex)
#     else:
#         ins(name,age)





#7、打印功能菜单、添加学生信息、删除学生信息、修改学生信息、显示学生信息、退出系统，
# 接收输入，在根据输入内容调用相应函数实现相应功能（存入文件）
# 模板图如下。每次对学生管理系统发生改动，要写入改动点到log.txt文本中
# def ins():
#     while True:
#         print("1.添加学生信息")
#         print("2.删除学生信息")
#         print("3.修改学生信息")
#         print("4.显示学生信息")
#         print("5.退出")
#
#         a= input("请选择选项:")
#
#         if a=="1":
#             id = input("请输入要添加的学生学号:")
#
#             with open("student.txt","r",encoding="utf-8") as b:
#                 data=b.read()    #读取
#             if f"学生学号为:{id}"  not in data:
#                 name=input("请输入学生姓名:")
#                 address=input("请输入学生地址:")
#
#                 with open("student.txt","a",encoding="utf-8") as b:
#                     b.write(f"学生学号为:{id},学生姓名:{name},学生地址:{address}\n")#写入
#                     print(f"添加成功:学生学号为:{id},学生姓名:{name},地址:{address}")
#
#                 with open("log.txt","a",encoding="utf-8") as b:
#                     b.write(f"时间:{datetime.now()},新增:学生学号为:{id},学生姓名:{name},学生地址:{address}\n")#变动留痕写入
#
#             else:
#                 print(f"学生学号:{id}已存在,添加失败")
#
#                 with open("log.txt","a",encoding="utf-8") as b:
#                     b.write(f"时间:{datetime.now()},新增失败:学生学号为:{id}已存在\n")
#
#         elif a=="2":
#             id=input("请输入要删除的学生学号:")
#
#             with open("student.txt", "r", encoding="utf-8") as b:
#                 data = b.read()  # 读取
#
#             if f"学生学号为:{id}" not in data:
#                 print(f"删除失败,学生学号:{id}不存在")
#                 with open("log.txt", "a", encoding="utf-8") as b:
#                     b.write(f"时间:{datetime.now()},删除失败:学生学号为:{id}不存在\n")
#
#             else:
#                     with open("student.txt","r",encoding="utf-8") as b:
#                         list1=b.readlines()   #读取成列表形式
#
#                         for i in list1:
#                             if f"学生学号为:{id}" in i:
#                                 list1.remove(i)
#                             print(f"学生学号{id}删除成功")
#
#                     with open("student.txt", "w", encoding="utf-8") as b:
#                         b.writelines(list1)
#
#                     with open("log.txt", "a", encoding="utf-8") as b:
#                         b.write(f"时间:{datetime.now()},删除成功:学生学号为:{id}\n")
#
#         elif a=="3":
#             id=input("请输入要修改的学生信息对应的学号:")
#             with open("student.txt", "r", encoding="utf-8") as b:
#                 data = b.read()
#                 print(data)
#
#             if f"学生学号为:{id}" not in data:
#                 print(f"修改失败,学生学号{id}不存在")
#                 with open("log.txt", "a", encoding="utf-8") as b:
#                     b.write(f"时间:{datetime.now()},修改失败:学生学号为:{id}不存在\n")
#             else:
#                 name = input("请输入学生姓名:")
#                 address = input("请输入学生地址:")
#
#                 with open("student.txt", "r", encoding="utf-8") as b:
#                     list1=b.readlines()    #输出是一个列表内["学号1:,姓名1:,地址1:"   ,  "学号2:,姓名2:,地址2:"]
#                     for i in list1:    #i指的是某一行"学号1:,姓名1:,地址1:"
#                         if f"学生学号为:{id}" in i:
#                             list1.remove(i)
#                 list1.append(f"学生学号为:{id},学生姓名:{name},地址:{address}\n")
#                 print(f"学号{id}的信息修改成功,为:姓名:{name},地址:{address}")
#
#                 with open("student.txt", "w", encoding="utf-8") as b:
#                     b.writelines(list1)
#
#                 with open("log.txt", "a", encoding="utf-8") as b:
#                     b.write(f"时间:{datetime.now()},修改学号{id}的学生信息成功,新信息为:学生姓名为:{name},地址:{address}\n")
#
#         elif a=="4":
#             with open("student.txt", "r", encoding="utf-8") as b:
#                 data=b.readlines()
#                 if data:
#                     for index,line in enumerate(data):
#                         print(f"第{index+1}的学生信息为:{line}")
#                 else:
#                     print("数据空")
#         elif a=="5":
#             print("再见")
#             break
#
# ins()
























#8、下面是一个简单的好友管理系统的功能菜单（存入文件）
#好友管理系统中有5个功能:
#1.添加好友：用户根据提示“请输入要添加的好友：”添加后会提示“好友添加成功”。
#2.删除好友：用户根据提示“请输入删除好友姓名：”删除后提示“删除成功”
#3.备注好友：用户根据提示“请输入要修改的好友姓名：”和“请输入修改后的好友姓名：”修改后会提示“备注成功”。
#4.展示好友：若用户还没有添加过好友，提示“好友列表为空”，否则返回每个好友的姓名。
#5.退出：关闭好友管理系统。
# 文件读取要使用相对路径，确保在任何的电脑、终端都可以运行

# dict1=[]
# while True:
#     print("1.添加好友:")
#     print("2.删除好友:")
#     print("3.备注好友:")
#     print("4.显示好友:")
#     print("5.退出")
#     a= input("请选择选项:")
#     print(dict1)
#
#
#     if a=="1":
#         name = input("请输入要添加的好友：")
#         if name not in dict1:
#             print(f"好友{name}添加成功")
#             dict1.append(name)
#             print(dict1)
#
#             with open("haoyou.py","a",encoding="utf-8") as b:
#                 b.write(f"{name}\n")
#         else:
#             print("添加失败,好友{name}已存在")
#
#     elif a=="2":
#         name = input("请输入删除好友姓名:")
#         if name in dict1:
#             dict1.remove(name)
#             print(f"好友{name}删除成功")
#
#             with open("haoyou.py","a",encoding="utf-8") as b:
#                 b.write(f"{name}已删除\n")
#             print(dict1)
#
#         else:
#             print(f"删除失败,好友{name}不存在")
#
#
#     elif a=="3":
#         name_old=input("请输入要修改的好友姓名：:")
#         if name_old in dict1:
#             name_new=input("请输入修改后的好友姓名:")
#             dict1.append(name_new)  #吧老姓名的value信息移到新姓名那
#             dict1.remove(name_old)
#             print(f"原学生姓名:{name},已更改为:{name_new}")
#
#             with open("haoyou.py","a",encoding="utf-8") as b:
#                 b.write(f"{name_old}已删除,更改为{name_new}\n")
#             print(dict1)
#
#         else:
#             print(f"更改失败,原好友名{name_old}不存在")
#
#     elif a=="4":
#         with open("haoyou.py","r",encoding="utf-8") as b:
#             print(b.readlines())
#             print(dict1)
#     elif a=="5":
#         break
